package com.example.myapplication.ViewPageFragment;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.ArrayList;
import java.util.List;

public class ViewPager2Adapter2 extends FragmentStateAdapter {

    //片段数组
    List<Fragment> fragmentList = new ArrayList<>();
    //视图翻页器2适配器2（片段管理者，生命周期，片段数组）
    public ViewPager2Adapter2(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle,List<Fragment> fragments) {
        super(fragmentManager, lifecycle);
        fragmentList = fragments;
    }

    @NonNull
    @Override
    //创建片段
    public Fragment createFragment(int position) {
        //获取位置
        return fragmentList.get(position);

    }

    @Override
    //获取片段数组的长度
    public int getItemCount() {
        return fragmentList.size();
    }
}
